<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{path:'/home/goods'}">商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 筛选栏 -->
    <div style="margin: 15px 0">
      <el-input
        v-model="goodsObj.query"
        placeholder="请输入内容"
        class="input-with-select"
        style="width:300px"
        @keyup.enter.native="init"
      >
        <el-button slot="append" icon="el-icon-search" @click="init"></el-button>
      </el-input>
      <el-button style="margin-left:15px" type="success" plain @click="$router.push({name: 'AddGoods'})">添加商品</el-button>
    </div>
    <!-- 商品表格展示区域 -->
    <el-table :data="goodsList" style="width: 100%" :border="true">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column label="商品名称" prop="goods_name">
      </el-table-column>
      <el-table-column label="商品价格" width="100" prop="goods_price">
      </el-table-column>
      <el-table-column label="商品状态" width="80" prop="goods_state">
      </el-table-column>
      <el-table-column label="商品重量" width="100" prop="goods_weight">
      </el-table-column>
      <el-table-column label="创建时间" width="140" prop="add_time">
      </el-table-column>
      <el-table-column label="操作" width="260">
          <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
            <el-button type="info" icon="el-icon-edit"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
            <el-button type="warning" icon="el-icon-delete"></el-button>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" content="审核" placement="bottom">
            <el-button type="success" icon="el-icon-check"></el-button>
          </el-tooltip>
      </el-table-column>
    </el-table>
    <!-- 分页按钮部分 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="goodsObj.pagenum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="goodsObj.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="goodsList.total">
    </el-pagination>
  </div>
</template>
<script>
import { getGoodsList } from '@/api/goods.js'
export default {
  data () {
    return {
      goodsObj: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      goodsList: [
        {
          total: 0,
          goods_id: null,
          goods_name: '',
          goods_price: null,
          goods_number: null,
          goods_weight: null,
          goods_state: null,
          add_time: null,
          upd_time: null,
          hot_mumber: null,
          is_promote: null
        }
      ]
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      getGoodsList(this.goodsObj)
        .then(res => {
        //   console.log(res)
          this.goodsList = res.data.data.goods
          this.goodsList.total = res.data.data.total
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 分页按钮
    handleSizeChange (val) {
      this.goodsObj.pagesize = val
      this.init()
    },
    handleCurrentChange (val) {
      this.goodsObj.pagenum = val
      this.init()
    }
  }
}
</script>
<style lang="less" scoped>
</style>
